import { EventTouch } from "cc";
import { ViewBackState, ViewLayer, ViewMode } from "../../../../framework/view/ViewConsts";
import { ViewCtrlBase } from "../../../../framework/view/ViewCtrlBase";
import ViewMsgBox from "../view/ViewMsgBox";
import StringUtils from '../../../../framework/utils/StringUtils';

/**弹窗类型 */
export enum MsgBoxType {
    /**只有中间确定按钮 */
    OK,
    /**确定和取消按钮 */
    OK_CANCEL,
}

export interface MsgBoxData {
    type: MsgBoxType,
    title: string,
    msg: string,
    btn_str_ok?: string,
    btn_str_cancel?: string,
    /**是否隐藏关闭按钮 */
    hide_btn_close?: boolean,
    /**是否点击空白处关闭 */
    bg_close?: boolean,
    /**是否阻止返回键关闭 */
    no_back_close?:boolean,
    ok_callback?: (ev?: EventTouch) => void,
    cancel_callback?: (ev?: EventTouch) => void,
}


export default class VCMsgBox extends ViewCtrlBase {
    public static viewName: string = "ViewMsgBox";
    public static viewMode: ViewMode = ViewMode.MULTI;
    public viewLayer: ViewLayer = ViewLayer.Layer_MsgBox;
    public viewClass: (typeof ViewMsgBox) = ViewMsgBox;

    public get title() { return this.params.title; }
    public get msg() { return this.params.msg; }
    public get btnStrOk() { return this.params.btn_str_ok || StringUtils.getStr("common_ui_ok"); }
    public get btnStrCancel() { return this.params.btn_str_cancel || StringUtils.getStr("common_ui_cancel"); }
    public get type() { return this.params.type; }
    public get hideBtnClose() { return !!this.params.hide_btn_close; }
    public get bgClose() { return !!this.params.bg_close; }
    public get noBackClose() { return !!this.params.no_back_close; }
   
    onOpen() {
        super.onOpen();
        this.viewDoAction("initView");
    }

    onClose() {
        super.onClose();
    }
    /**注册系统事件 */
    registEvent(): void {

    }

    checkCanBack() {
        if (this.noBackClose) {
            return ViewBackState.Return;
        }
        return ViewBackState.Close;
    }

    onClickOk(ev: EventTouch) {
        this.params.cancel_callback && this.params.ok_callback(ev);
        this.close();
    }

    onClickCancel(ev: EventTouch) {
        if (this.type === MsgBoxType.OK) {
            this.onClickOk(ev);
            return;
        }
        this.params.cancel_callback && this.params.cancel_callback(ev);
        this.close();
    }

}